var amqp = require('amqplib/callback_api');

amqp.connect('amqp://Arrcen:arrcen911@59.110.172.150:5672/', function (err, conn) {
    if (err) { exit(err); }
    conn.createChannel(function (err, ch) {
        if (err) { exit(err); }

        // var ex = 'lg.RefundMessage';
        var ex = 'Arrcen.EventMessageExchange.ChanJoy.Messaging.Model.HisMessage.RefundMessage';

        ch.assertExchange(ex, 'fanout', {durable: false});
        
        var q = 'lg.refundTest';

        ch.assertQueue(q, { durable: false });
        ch.bindQueue(q, ex, '');

        console.log(" [*] Waiting for refund messages in %s. To exit press CTRL+C", q);
        ch.consume(q, function (msg) {
            console.log(" [*] Received %s", msg.content.toString());
        }, { noAck: true });
    })
});

function exit(err) {
    console.log(err);
    process.exit(1);
}